package 力扣日常刷题.木22二月.第17天223;

/**
 * @author 帅小伙
 * @date 2022/2/23
 * @description
 */
public class Demo142搜素插入的位置 {


    public int searchInsert(int[] nums, int target) {
        int n = nums.length;
        if(n == 0) return 0;
        int l = 0, r = n;
        while(l < r) {
            int mid = (l+r) / 2;
            if(target == nums[mid]) return mid;
            else if(target < nums[mid]) r = mid;
            else l = mid + 1;
        }
        return l;
    }

}
